package com.beeway.blackgoose.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.beeway.blackgoose.R;
import com.lidroid.xutils.BitmapUtils;
import java.util.List;

public abstract class MyBaseAdapter<T> extends BaseAdapter {

    public Context context;
    public List<T> list;
    public LayoutInflater inflate;
    public BitmapUtils bitmapUtils;

    public MyBaseAdapter(Context context, List<T> list, BitmapUtils bitmapUtils) {
        this.context = context;
        this.list = list;
        this.bitmapUtils = bitmapUtils;
        inflate = LayoutInflater.from(context);

        if (bitmapUtils != null) {
            initBitmapConfig();
        }
    }

    public void initBitmapConfig() {
//        config = new BitmapDisplayConfig();
//        config.setBitmapConfig(Bitmap.Config.RGB_565);
//        config.setLoadFailedDrawable(context.getResources().getDrawable(R.mipmap.logo_gray));
//        config.setLoadingDrawable(context.getResources().getDrawable(R.mipmap.logo_gray));
        bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);
        bitmapUtils.configDefaultLoadingImage(R.mipmap.ic_launcher);
        bitmapUtils.configDefaultLoadFailedImage(R.mipmap.ic_launcher);
    }

    @Override
    public int getCount() {
        return list != null && list.size() > 0 ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {

        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getItemView(position, convertView, parent);
    }

    public abstract View getItemView(int position, View convertView, ViewGroup parent);
}
